package com.baseframe.create1.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.baseframe.create1.R;
import com.baseframe.create1.flycotablayout.SlidingTabLayout;
import com.baseframe.create1.flycotablayout.ViewFindUtils;
import com.baseframe.create1.fragment.SimpleCardFragment;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/4/14.
 */

public class ZixunActivity extends BaseActivity implements View.OnClickListener {
    private Context mContext = this;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "头条", "双色球", "大乐透"
            , "福彩3D", "竞猜", "排列5", "北京单场"
    };
    private MyPagerAdapter mAdapter;

    ImageView img_btn_return;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zixun);
        img_btn_return = (ImageView) findViewById(R.id.img_btn_return);
        img_btn_return.setOnClickListener(this);
        for (String title : mTitles) {
            mFragments.add(SimpleCardFragment.getInstance(title));
        }
        View decorView = getWindow().getDecorView();
        ViewPager vp = ViewFindUtils.find(decorView, R.id.vp);
        mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        vp.setAdapter(mAdapter);
        /** indicator圆角色块 */
        SlidingTabLayout tabLayout_10 = ViewFindUtils.find(decorView, R.id.tl_3);
        tabLayout_10.setViewPager(vp);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.img_btn_return:
                finish();

                break;
        }
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
